package com.didispace;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@EnableDiscoveryClient
@SpringBootApplication
public class TraceApplication {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	// p388
	@RequestMapping(value = "/trace-2", method = RequestMethod.GET)
	public String trace() {
		// for(int i=0; i<10; i++) {
		// 	logger.info("===<call trace-2>===" + i);
		// }
		logger.info("===<call trace-2>===");
		return "Trace";
	}

	// 可以通过对trace-2 的实现做一些修改来输出这些头部信息  p391
	// @RequestMapping(value = "/trace-2", method = RequestMethod.GET)
	// public String trace(HttpServletRequest request) {
	// 	logger.info("===<call trace-2, TraceId={}, SpanId={}>===",
	// 			request.getHeader("X-B3-TraceId"), request.getHeader("X-B3-SpanId"));
	// 	return "Trace";
	// }

	public static void main(String[] args) {
		SpringApplication.run(TraceApplication.class, args);
	}

}
